﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace com.core.controls
{
    /*
     Expected:
    <ext:Validator runat="server" ID="ctrlValidator" ValidationFunction="valInputs">
    <Items>
    <ext:InputRequireValidation ControlToValidateID="ctrl1" Message="res::RequiredField" />
    <ext:TextBoxAlphaNumericValidation ControlToValidateID="ctrl1" Message="res::OnlyAlphaNumericMsg" />
    <ext:TextBoxEmailValidation ControlToValidateID="ctrl1" Message="res::InvalidEmail" />
    <ext:TextBoxInvalidCharactersValidation  InvalidCharacters="<>" ControlToValidateID="ctrl1" Message="res::InvalidCharactersMsg" />
    <ext:TextBoxValidCharactersValidation ValidCharacters="<>" ControlToValidateID="ctrl1" Message="res::InvalidCharactersMsg" />
    </Items>
    </ext:Validator>
     */
    public class Validator : System.Web.UI.WebControls.Repeater
    {
        public List<ControlValidation> Items { get; private set; }
        public string ClientFunctionName { get; set; }
        public Validator()
        {
            Items = new List<ControlValidation>();
        }
        public bool IsValid()
        {
            return true;
        }
    }
    public abstract class ControlValidation
    {
        
        public string ClientFunction { get; set; }
        public string ControlToValidateID { get; set; }
        public string Message { get; set; }
        protected virtual bool OnServerValidate() { return true; }
        protected System.Web.UI.Control ValidatedControl
        {
            get
            {
                //more core here
                return new System.Web.UI.Control();
            }
        }
    }
    public class InputRequireValidation : ControlValidation
    {

    }
    public class TextBoxValidCharactersValidation : ControlValidation
    {
        public string ValidCharacters { get; set; }
    }
    public class TextBoxInvalidCharactersValidation : ControlValidation
    {
        public string InvalidCharacters { get; set; }

    }
    public class TextBoxEmailValidation : ControlValidation
    {

    }
    public class TextBoxRegularValidation : ControlValidation
    {

    }
    public class CustomValidation : ControlValidation
    {
        public delegate bool ServerValidationHandler(System.Web.UI.Control ctrl);
        public event ServerValidationHandler ServerValidate;
        protected override bool OnServerValidate()
        {
            if (ServerValidate != null)
            {
                return ServerValidate(ValidatedControl);
            }
            return base.OnServerValidate();
        }

    }
}
